package com.woniuxy.oa.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.woniuxy.oa.entity.PageBeanList;
import com.woniuxy.oa.entity.WorkPlan;
import com.woniuxy.oa.exception.WorkPlanException;
import com.woniuxy.oa.mapper.WorkPlanMapper;
import com.woniuxy.oa.service.WorkPlanService;

/**
 * WorkPlanService层的实现类
 * @author 35925
 *
 */
@Service
public class WorkPlanServiceImpl implements WorkPlanService{

	@Autowired
	WorkPlanMapper workPlanMapper;
	
	/**
	 * 查询所有人的工作计划
	 */
	@Override
	public List<WorkPlan> getAllWorkPlan() {
		List<WorkPlan> workPlans=null;
		try {
			workPlans = workPlanMapper.selectAllWorkPlan();
		} catch (Exception e) {
			throw new WorkPlanException(e);
		}
		return workPlans;
	}

	/**
	 * 添加某人的工作计划
	 */
	@Override
	public void addWorkPlan(WorkPlan workPlan) {
		try {
			workPlanMapper.insertWorkPlan(workPlan);
		} catch (Exception e) {
			throw new WorkPlanException(e);
		}
	}

	/**
	 * 修改某位员工工作计划的方法
	 */
	@Override
	public void modifyWoekPlan(WorkPlan workPlan) {
		try {
			workPlanMapper.updateWoekPlan(workPlan);
		} catch (Exception e) {
			throw new WorkPlanException(e);
		}
	}

	/**
	 * 删除某位员工的方法
	 */
	@Override
	public void removeWorkPlan(Integer w_id) {
		try {
			workPlanMapper.deleteWorkPlan(w_id);
		} catch (Exception e) {
			throw new WorkPlanException(e);
		}
	}

	/**
	 * 根据工作计划id查询工作计划
	 */
	@Override
	public WorkPlan getWorkPlanByW_id(Integer w_id) {
		WorkPlan workPlan=null;
		try {
			workPlan = workPlanMapper.selectWorkPlanByW_id(w_id);
		} catch (Exception e) {
			throw new WorkPlanException(e);
		}
		return workPlan;
	}

	/**
	 * 这是按条件查询
	 */
	@Override
	public PageBeanList<WorkPlan> getWorkPlanConditionByPage(int pageIndex, int pageSize, WorkPlan workPlan) {
		//获取总条数
		int totalRecored = workPlanMapper.selectWorkPlanConditionByPageTotalRecored(workPlan);
		//获取模糊查询出来的信息
		List<WorkPlan> workplans = workPlanMapper.selectWorkPlanConditionByPage((pageIndex-1)*pageSize, pageSize, workPlan);
		//获取自己定义的泛型类
		PageBeanList<WorkPlan> pageBean=new PageBeanList<WorkPlan>();
		//给pageBean的BeanList赋值
		pageBean.setBeanList(workplans);
		//把当前页面的页码赋值进去
		pageBean.setPageIndex(pageIndex);
		//把每页显示的页码赋值进去
		pageBean.setPageSize(pageSize);
		//把数据库查询出来的总条数赋值进去
		pageBean.setTotalRecored(totalRecored);
		//调用自己定义类里面自己写的方法   做最后调整   
		pageBean.setPageBeginAndPageEnd();
		return pageBean;
	}

}
